package com.yumeng.framework.auth.shiro.token;

import com.yumeng.framework.auth.bean.TokenInfo;
import org.apache.shiro.authc.HostAuthenticationToken;


/**
 * JWT 令牌
 * @author wxd
 * @date 2022/4/13 10:01
 */
public class JwtToken implements HostAuthenticationToken {

    private static final long serialVersionUID = -6824562468724806764L;

    private final String token;
    private final String refreshToken;
    private final String host;

    public JwtToken(String token, String refreshToken, String host){
        this.token = token;
        this.refreshToken = refreshToken;
        this.host = host;
    }


    @Override
    public String getHost() {
        return this.host;
    }

    @Override
    public Object getPrincipal() {
        return this.token;
    }

    @Override
    public Object getCredentials() {
        return this.token;
    }

    public String getToken() {
        return token;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    @Override
    public String toString() {
        return "JwtToken{" +
                "token='" + token + '\'' +
                ", refreshToken='" + refreshToken + '\'' +
                ", host='" + host + '\'' +
                '}';
    }

    public static TokenInfo createTokenInfo(JwtToken token){
        return new TokenInfo(token.getToken(), token.getRefreshToken());
    }
}
